//Allocator for small & little data blocks 
// $Id: alloc_lite.h 568 2010-10-25 15:41:07Z Oleg.Bulychov $
#pragma once

#include "src/heo/include/mem_util.h"

//__________________________________________________________________________________
//__________________________________________________________________________________
class lite_allocator
{
public:
    static bool construct(int nMaxThreads, size_t mb) NO_THROW_();//:call from main thread!
    static void destruct() NO_THROW_();//:call from main thread!
//.............................................................................
    static void* Alloc(size_t cbSize) NO_THROW_();
//.............................................................................
    static void* Alloc(size_t cbSize, mem_util::no_check_null_t const&) NO_THROW_();
//.............................................................................
    template<typename T>
    static T* Alloc() NO_THROW_()
    {
        return (T*)Alloc(sizeof(T));
    }
//.............................................................................
    template<typename T>
    static T* Alloc(mem_util::no_check_null_t const& no_check_null) NO_THROW_()
    {
        return (T*)Alloc(sizeof(T), no_check_null);
    }
//.............................................................................
    static void Free(void* ptr, size_t cbSize) NO_THROW_();
//.............................................................................
    template<typename T>
    static void Free(T* ptr) NO_THROW_()
    {
        Free(ptr, sizeof(T));
    }
//.............................................................................
//.............................................................................
    static void enter_Thread(int nRank) NO_THROW_();
    static void leave_Thread(int nRank) NO_THROW_();
//.............................................................................
//.............................................................................
    static size_t get_Max_Item_Size() NO_THROW_();
//.............................................................................
    static void report(std::ostream& os);
//.............................................................................
};
//__________________________________________________________________________________
class lite_object
{
public:
    static void* operator new(size_t size) NO_THROW_()
    {
        return lite_allocator::Alloc(size);
    }
//.............................................................................
    static void operator delete(void* p, size_t size) NO_THROW_()
    {
        lite_allocator::Free(p, size);
    }
//.............................................................................
    static void* operator new(size_t size, void* place) NO_THROW_()
    {
        return ::operator new(size, place);
    }
//.............................................................................
    static void operator delete(void* p, void* place) NO_THROW_()
    {
        ::operator delete(p, place);
    }
//.............................................................................
//.............................................................................
};

//EOF!
